const treeData = {  
    id: 1,  
    name: "Root",  
    children: [  
      {  
        id: 2,  
        name: "Child 1",  
        children: [  
          {  
            id: 4,  
            name: "Grandchild 1",  
            children: []  
          },  
          {  
            id: 5,  
            name: "Grandchild 2",  
            children: []  
          }  
        ]  
      },  
      {  
        id: 3,  
        name: "Child 2",  
        children: []  
      }  
    ]  
  };
  function find(node,targetId){
    if(targetId===node.id){
        return node
    }
   if(node.children&&node.children.length>0){
    for(let child of node.children){//这里容易出错，是在node的孩子中遍历 而不是遍历node
        let res=find(child,targetId)
        if(res){
            return res
        }

    }
    }

  }
  let a=find(treeData,4)
  console.log(a);
  